package com.aquan.map_jetpack.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.accompanist.systemuicontroller.rememberSystemUiController

@Composable
fun TopAppBar(statusBarHeight: Int = 20, content: @Composable () -> Unit) {

    val systemUiController = rememberSystemUiController()

    val tabBarHeight = 56.dp


    LaunchedEffect(key1 = Unit) {
        systemUiController.setStatusBarColor(Color.Transparent)
    }

    val statusBarHeightDp = with(LocalDensity.current) {
        statusBarHeight.toDp()
    }

    Row(
        Modifier
            .background(
                Brush.linearGradient(
                    listOf(
                        MaterialTheme.colors.primary,
                        MaterialTheme.colors.secondary
                    )
                )
            )
            .fillMaxWidth()
            .height(tabBarHeight + statusBarHeightDp)
            .padding(statusBarHeightDp),
        horizontalArrangement = Arrangement.Center,
        verticalAlignment = Alignment.CenterVertically

    ) {
        content()
    }
}

@Preview
@Composable
fun TopAppBarPreview() {
    TopAppBar(20) {
        Text(text = "你好哇", color = Color(0xFFFFFFFF))
    }
}